﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataControl;
using System.Data;
using System.Text;
using System.Collections;

namespace ATW.MT.BUS
{
    public class bus_T_sort
    {
        DataAccess da = null;
        public bus_T_sort()
        {
            da = new DataAccess();
        }
        #region 方法
        public DataTable getFT(string pid)
        {//阀体
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select pm.ID,
	                           case when M.Material_code=M.Material_code_z then M.Material_code
			                        else M.Material_code+'/'+M.Material_code_z end name 
                        from [T_Production_Material] pm 
                        left join C_Material M on M.MID=pm.MID
                        where ProductionID='{0}' and pm.type='4'
                        order by pm.RowId asc", pid);
            return da.ExecuteDataTable(sql.ToString());
        }
        public bool setMaterial(string[] list)
        {//材质顺序
            if (list != null && list.Length > 0)
            {
                ArrayList Al = new ArrayList();
                for (int i = 0; i < list.Length; i++)
                {
                    Al.Add("update T_Production_Material set rowid='" + i + "' where id='" + list[i] + "'");
                }
                return da.ExecuteArrayList(Al);
            }
            return false;
        }
        public DataTable getFG(string pid)
        {//阀杆
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select pm.ID,
	                           case when M.Material_code=M.Material_code_z then M.Material_code
			                        else M.Material_code+'/'+M.Material_code_z end name 
                        from [T_Production_Material] pm 
                        left join C_Material M on M.MID=pm.MID
                        where ProductionID='{0}' and pm.type='2'
                        order by pm.RowId asc", pid);
            return da.ExecuteDataTable(sql.ToString());
        }
        public DataTable getFB(string pid)
        {//阀瓣
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select pm.ID,
	                           case when M.Material_code=M.Material_code_z then M.Material_code
			                        else M.Material_code+'/'+M.Material_code_z end name 
                        from [T_Production_Material] pm 
                        left join C_Material M on M.MID=pm.MID
                        where ProductionID='{0}' and pm.type='3'
                        order by pm.RowId asc", pid);
            return da.ExecuteDataTable(sql.ToString());
        }
        public DataTable getFZ(string pid)
        {//阀座
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select pm.ID,
	                           case when M.Material_code=M.Material_code_z then M.Material_code
			                        else M.Material_code+'/'+M.Material_code_z end name 
                        from [T_Production_Material] pm 
                        left join C_Material M on M.MID=pm.MID
                        where ProductionID='{0}' and pm.type='1'
                        order by pm.RowId asc", pid);
            return da.ExecuteDataTable(sql.ToString());
        }
        public DataTable getTL(string pid)
        {//填料
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select pm.ID,
	                           case when M.Material_code=M.Material_code_z then M.Material_code
			                        else M.Material_code+'/'+M.Material_code_z end name 
                        from [T_Production_Material] pm 
                        left join C_Material M on M.MID=pm.MID
                        where ProductionID='{0}' and pm.type='5'
                        order by pm.RowId asc", pid);
            return da.ExecuteDataTable(sql.ToString());
        }
        public DataTable getKJ(string pid)
        {//口径
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select S.SID ID,
	                               (S.Size_Code_C+'|'+S.Size_Code_S) name from T_Production_Size PS
                            inner join C_Size S on PS.SID=S.SID
                            where PS.ProductionID='{0}'
                            order by S.RowId asc ", pid);
            return da.ExecuteDataTable(sql.ToString());
        }
        public bool setSize(string[] list)
        {//尺寸排序
            if (list != null && list.Length > 0)
            {
                ArrayList al = new ArrayList();
                for (int i = 0; i < list.Length; i++)
                {
                    al.Add("update C_Size set rowid='" + i + "' where SID='" + list[i] + "'");
                }
                return da.ExecuteArrayList(al);
            }
            return false;
        }
        public DataTable getYL(string pid)
        {//压力等级
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select P.PressureID ID,
	                                   (P.Pressure_Code_C+'|'+P.Pressure_Code_S) name from T_Production_Pressure PP
                                inner join C_PressureLevel P on PP.PressureID=P.PressureID
                                where PP.ProductionID='{0}'
                                order by P.RowId asc", pid);
            return da.ExecuteDataTable(sql.ToString());
        }
        public bool setPressure(string[] list)
        {//设置压力等级
            if (list != null && list.Length > 0)
            {
                ArrayList al = new ArrayList();
                for (int i = 0; i < list.Length; i++)
                {
                    al.Add("update C_PressureLevel set rowid='" + i + "' where PressureID='" + list[i] + "'");
                }
                return da.ExecuteArrayList(al);
            }
            return false;
        }
        public DataTable getSJ(string pid)
        {//设计
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select DL.DesignLevelID ID,
	                               DL.[Desc] name from T_Production_Design PD
                            left join C_DesignLevel DL on PD.DesignLevelID=DL.DesignLevelID
                            where PD.ProductionID='{0}'
                            order by DL.RowId asc", pid);
            return da.ExecuteDataTable(sql.ToString());
        }
        public bool setDesign(string[] list)
        {//设计等级顺序
            ArrayList al = new ArrayList();
            if (list != null && list.Length > 0)
            {
                for (int i = 0; i < list.Length; i++)
                {
                    al.Add("update C_DesignLevel set rowid='" + i + "' where DesignLevelID='" + list[i] + "'");
                }
                return da.ExecuteArrayList(al);
            }
            return false;
        }
        public DataTable getLJ(string pid)
        {//连接方式
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select C.ConnID ID,
	                                   (CM.[desc]+'('+CM2.[desc]+')')name from T_Production_Conn PC
                                left join C_Connection C on PC.ConnID=C.ConnID
                                left join C_Connection_MultiLan CM on C.ConnID=CM.ConnID and CM.LanId='zh'
                                left join C_Connection_MultiLan CM2 on C.ConnID=CM2.ConnID and CM2.LanId='en'
                                where PC.ProductionID='{0}'
                                order by C.RowId asc", pid);
            return da.ExecuteDataTable(sql.ToString());
        }
        public bool setConn(string[] list)
        {//连接方式顺序
            ArrayList al = new ArrayList();
            if (list != null && list.Length > 0)
            {
                for (int i = 0; i < list.Length; i++)
                {
                    al.Add("update C_Connection set rowid='" + i + "' where ConnID='" + list[i] + "'");
                }
                return da.ExecuteArrayList(al);
            }
            return false;
        }
        public DataTable getFJ(string pid)
        {//法兰标准
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select CF.FranLevelID ID,
	                       CF.[Desc] name from T_Production_Fran PF
                    left join C_FranLevel CF on PF.FranLevelID=CF.FranLevelID
                    where PF.ProductionID='{0}'
                    order by CF.RowId asc", pid);
            return da.ExecuteDataTable(sql.ToString());
        }
        public bool setFran(string[] list)
        {//法兰标准排序
            ArrayList al = new ArrayList();
            if (list != null && list.Length > 0)
            {
                for (int i = 0; i < list.Length; i++)
                {
                    al.Add("update C_FranLevel set rowid='" + i + "' where FranLevelID='" + list[i] + "'");
                }
                return da.ExecuteArrayList(al);
            }
            return false;
        }
        public DataTable getJG(string pid)
        {//结构标准
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select CS.StructLevelID ID,
	                                   CS.[Desc] name from T_Production_Struct PS
                                left join C_StructLevel CS on PS.StructLevelID=CS.StructLevelID
                                where PS.ProductionID='{0}'
                                order by CS.RowId asc", pid);
            return da.ExecuteDataTable(sql.ToString());
        }
        public bool setStruct(string[] list)
        {//结构标准排序
            ArrayList al = new ArrayList();
            if (list != null && list.Length > 0)
            {
                for (int i = 0; i < list.Length; i++)
                {
                    al.Add("update C_StructLevel set rowid='" + i + "' where StructLevelID='" + list[i] + "'");
                }
                return da.ExecuteArrayList(al);
            }
            return false;
        }
        public DataTable getMF(string pid)
        {//结构标准
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select S.SealLevelID ID,
	                               (case when S.Level='无等级区分' then S.LevelType else S.LevelType+' '+S.Level end) name from T_Production_Seal PS
                            left join C_SealLevel S on PS.SealLevelID=S.SealLevelID
                            where PS.ProductionID='{0}'
                            order by S.RowId asc", pid);
            return da.ExecuteDataTable(sql.ToString());
        }
        public bool setSeal(string[] list)
        {//结构标准排序
            ArrayList al = new ArrayList();
            if (list != null && list.Length > 0)
            {
                for (int i = 0; i < list.Length; i++)
                {
                    al.Add("update C_SealLevel set rowid='" + i + "' where SealLevelID='" + list[i] + "'");
                }
                return da.ExecuteArrayList(al);
            }
            return false;
        }
        #endregion
    }
}